Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Begin deprecation cycle of the discrete pulse library #10222

Merged
merged 10 commits into from
Jul 4, 2023

Conversation

TsafrirA
Copy link
Collaborator

@TsafrirA TsafrirA commented Jun 7, 2023

Summary

The discrete pulse library serves little purpose today, as the SymbolicPulse class and library offer the same functionality at reduced computational cost. This PR completes the SymbolicPulse counterparts to the discrete library, and begins the deprecation cycle for it.

Details and comments

The discrete pulse library serves little purpose today, as the SymbolicPulse class and library offer the same functionality at reduced computational cost. Furthermore, it is desired to change the naming convention of the pulses in the symbolic pulse library from camel case to snake case, to reflect the fact that they are no longer subclasses of SymbolicPulse. This change is not possible because of naming conflicts with the discrete pulses. For these reasons, it was decided to deprecate the discrete library.

This PR:

  • Adds new SymbolicPulses to the library, to recreate the functionality of all discrete pulses (namely, Sech,SechDeriv,GaussianDeriv,Square). Because of the aforementioned naming conflict, the functions use camel case notation.
  • Raises PendingDeprecationWarning for all pulses in the discrete library, with detailed info about the SymbolicPulse counterpart.

With a few minor exceptions, the SymbolicPulse library recreates the same behavior as the discrete library. The one notable difference is the adoption of the (amp,angle) representation in the symbolic library.

Debatable decisions

  • Some of the new pulses seem a bit underwhelming in their SymbolicPulse form. While Waveforms can be added, the same is not true for SymbolicPulses - and this probably removes the prominent use case for GaussianDeriv and SechDeriv. (One can consider a DRAG version with Sech instead of Gaussian, but SechDeriv on its own makes little sense to me.)
  • Some duplicated tests for the new pulses might be excessive (mainly limit_amplitude and limit_amplitude_per_instance).

@TsafrirA TsafrirA requested review from a team, eggerdj and wshanks as code owners June 7, 2023 10:24
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core
  • @nkanazawa1989

@nkanazawa1989 nkanazawa1989 added the mod: pulse Related to the Pulse module label Jun 7, 2023
@nkanazawa1989 nkanazawa1989 self-assigned this Jun 7, 2023
@nkanazawa1989 nkanazawa1989 added this to the 0.25.0 milestone Jun 7, 2023
@coveralls
Copy link

coveralls commented Jun 7, 2023

Pull Request Test Coverage Report for Build 5444281151

  • 60 of 60 (100.0%) changed or added relevant lines in 3 files are covered.
  • 6 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.04%) to 85.979%

Files with Coverage Reduction New Missed Lines %
qiskit/transpiler/passes/synthesis/unitary_synthesis.py 2 90.18%
crates/qasm2/src/lex.rs 4 90.63%
Totals Coverage Status
Change from base Build 5403762172: 0.04%
Covered Lines: 71556
Relevant Lines: 83225

💛 - Coveralls

Copy link
Contributor

@nkanazawa1989 nkanazawa1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick review for the first round. Overall this looks good to me. Do you have plans for continuous and sampler module deprecation? They are no longer useful after discrete is removed (Qiskit Dynamics user may use continuous to evaluate pulse value for upsampling).

qiskit/pulse/library/discrete.py Show resolved Hide resolved
since="0.25.0",
additional_msg="The discrete pulses library, including zero() is pending deprecation."
" Instead, use the SymbolicPulse library to create the waveform with"
" pulse.Constant(amp=0,...).get_waveform().",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also define Zero function in the symbolic pulse module that wraps Constant with amp=0.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion here. I don't know how much people actually use zero amplitude constants as spacers (@wshanks correctly pointed out elsewhere that there are use cases where you would want something like this) but I suspect it doesn't warrant the extra clutter in the code base.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a problem of backward compatibility of import. Once we remove this module, people cannot find zero in the pulse namespace and there is no alternative approach in terms of import. Likely this pulse is not significantly important and can go in this way.

" pulse.Square(...).get_waveform()."
" Note that pulse.Square() does not support complex values for `amp`."
" Instead, use two float values for (`amp`, `angle`)."
" Also note that the underlying `sign` function used to"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot understand this message without reading code. Maybe we can say new symbolic implementation may return different value at t=0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the problem is not with t=0 because the first time slot is evaluated at t=0.5. The problem arises only when the sin function is evaluated to exactly zero. This might not even happen (as the tests I added demonstrate). This is somewhat of an edge case. I am not sure how to handle it correctly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you can write more details (possibly with example code) in release note and say "read release note for more details" here? I don't really like lengthy warning as it might be raised many times.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted for matching the functional form of square() and Square(), so this discussion was almost mute. However, when I did that I noticed that the phase in square() was defined somewhat strangely, so I changed that, and now the warning addresses that - but it points the user to the documentation like you suggested.

@TsafrirA
Copy link
Collaborator Author

TsafrirA commented Jun 7, 2023

Thanks for quick review @nkanazawa1989 !
Regarding continuous and sampler - I am open to suggestions. They don't stand in the way of anything, so I don't see a clear need to remove them (but we might want to remove them nonetheless).

@nkanazawa1989
Copy link
Contributor

Thanks I just adde some suggestions in reply. We can probably deprecate continuous and sampler after we drop the discrete module?

Copy link
Contributor

@nkanazawa1989 nkanazawa1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good to me.

@nkanazawa1989 nkanazawa1989 added this pull request to the merge queue Jul 4, 2023
Merged via the queue into Qiskit:main with commit 8a8609f Jul 4, 2023
@TsafrirA TsafrirA deleted the DiscretePulseDeprecation branch October 25, 2023 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mod: pulse Related to the Pulse module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants